package org.luo.api.config;

import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.luo.common.utils.ThreadLocalUtil;
import org.springframework.context.annotation.Bean;

import java.util.Map;

public class FeignConfig {
    @Bean
    public Logger.Level feignLoggerLevel(){
        return Logger.Level.FULL;
    }
    @Bean
    public RequestInterceptor userInfoRequestInterceptor(){
        return new RequestInterceptor(){

            @Override
            public void apply(RequestTemplate requestTemplate) {
                Map<String, Object> map = ThreadLocalUtil.get();
                String username =(String) map.get("username");
                Integer id = (Integer) map.get("id");
                requestTemplate.header("username", username);
                requestTemplate.header("id", id.toString());
            }
        };
    }
}
